package com.example.springboot.mapper;

import com.example.springboot.entity.events;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Optional;

@Mapper
public interface EventMapper {

    @Select("SELECT * FROM events")
    List<events> findAll();

    @Select("SELECT * FROM events WHERE event_id = #{id}")
    Optional<events> findById(Long id);

    @Insert("INSERT INTO events (title, description, event_date, event_time, location) " +
            "VALUES (#{title}, #{description}, #{event_date}, #{event_time}, #{location})")
    @Options(useGeneratedKeys = true, keyProperty = "event_id")
    int save(events event);

    @Delete("DELETE FROM events WHERE event_id = #{id}")
    int deleteById(Long id);

    @Update("UPDATE events SET title = #{title}, description = #{description}, " +
            "event_date = #{event_date}, event_time = #{event_time}, location = #{location},organizer_id=#{organizer_id} " +
            "WHERE event_id = #{event_id}")
    int update(events event);

    @Insert("INSERT INTO events (title, description, event_date, event_time, location,organizer_id) " +
            "VALUES (#{title}, #{description}, #{event_date}, #{event_time}, #{location},#{organizer_id})")
    void insert(events event);

    @Select("SELECT * FROM events where organizer_id=#{id}")
    List<events> getAllEventsByid(Long id);
}
